package com.woniuxy.deadLetter;

import com.rabbitmq.client.*;
import com.woniuxy.utils.RabbitConnection;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

/**
 * @Author: linKe
 * @Date: 2022/1/10 16:37
 * @FileName: Consumer
 * @version: 1.0
 * @Description: 死信交换
 */
@Log4j2
public class ConsumerEmailDeadLetter {
    public static void main(String[] args) throws IOException, TimeoutException {
        // 连接通道
        Channel channel = RabbitConnection.getConnection().createChannel();
        // 一组正常
        channel.exchangeDeclare("exchangeTrue", BuiltinExchangeType.TOPIC);
        // 设置队列属性
        Map<String, Object> arguments = new HashMap<>(10);
        // 设置队列最大存放数量
        arguments.put("x-max-length", 20);
        // 死信交换机设置
        arguments.put("x-dead-letter-exchange","exchangeDeadLx");
        // 死信路由配置
        arguments.put("x-dead-letter-routing-key","deadLetterX");
        channel.queueDeclare("queueEmailTrueTest", true, false, false, arguments);
        channel.queueBind("queueEmailTrueTest", "exchangeTrue", "#.deadLx.#");


        // 死信交换机，路由绑定
        channel.exchangeDeclare("exchangeDeadLx", BuiltinExchangeType.TOPIC);
        channel.queueDeclare("queueDeadLxTest", true, false, false, null);
        channel.queueBind("queueDeadLxTest", "exchangeDeadLx", "#.deadLetterX.#");

    }
}
